** Run this file after running R code.

*1 Preprocessing data from R 
*Read the monthly files generated from R and preprocess them for Stata.
*input：  Raw_data\datacompile_natsums_monthly_yyyy.dta　(yyyy=2004~2019)
*output: stataMonthly\CP_yyyy.dta

        forvalues v = 2004(1)2019 {
			use "Stata_intermediate/Raw_data_stata/datacompile_natsums_monthly_`v'.dta",clear
			duplicates tag upc upc_ver_uc, g(n_month) 
			keep if n_month == 11
			keep upc yqVal pfsum_actualPaid price year	quarter upc_ver_uc
			merge m:1 upc upc_ver_uc using Stata_intermediate/Raw_data_stata/upcModLinkM.dta, keep(match) nogen 
			keep upc yqVal pfsum_actualPaid price year	quarter	product_module_code	upc_ver_uc
     		rename quarter month
			duplicates drop upc upc_ver_uc yqVal,force
			save "Stata_intermediate/stataMonthly/CP_`v'.dta",replace
        } 

*2. Obtain welfare relevant index and Chained index. Aggregation with Cobb-Douglas weight across modules
*Input files are CP_yyyy: 2004-2019.
*Output files are CP_merged and PriceAggregation/CP_AGG_yyyy.dta
*Module-level Welfare Relevant Inflation and Chianed Index are created and aggregated with the Cobb-Douglas function.
do MonthlyAggregation.do

*3. Output data for figures.
do Data_for_figure.do